<template>
  <div>
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="6">
            <a-form-item label="手机号">
              <a-input placeholder="请输入手机号" v-model:value="queryParam.username"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item label="名称">
              <a-input placeholder="请输入名称" v-model:value="queryParam.realname"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="searchQuery">查询</a-button>
                <a-button type="primary" preIcon="ant-design:reload-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)"/>
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <CaishuiPreItemsDrawer @register="registerDrawer"></CaishuiPreItemsDrawer>
  </div>
</template>

<script lang="ts" name="caishuiPreItems-caishuiPreItems" setup>
import {reactive, ref} from 'vue';
import {BasicTable, TableAction} from '/@/components/Table';
import {useListPage} from '/@/hooks/system/useListPage';
import {columns} from './CaishuiPreItems.data';
import {list} from './CaishuiPreItems.api';
import CaishuiPreItemsDrawer from './components/CaishuiPreItemsDrawer.vue'
import {useDrawer} from "/@/components/Drawer";

const queryParam = ref<any>({});
  const toggleSearchStatus = ref<boolean>(false);
  const registerModal = ref();
  const exportIconLoading = ref<boolean>(false);
  //注册drawer
  const [registerDrawer, { openDrawer }] = useDrawer();
  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      api: list,
      columns,
      canResize:false,
      useSearchForm: false,
      striped: true,
      showIndexColumn: true,
      actionColumn: {
        width: 150,
        fixed: 'right',
      },
      //自定义默认排序
      defSort: {
        column: 'id',
        order: 'desc',
      },
      beforeFetch: (params) => {
        return Object.assign(params, queryParam.value);
      },
    },
  });
  const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
  const labelCol = reactive({
    xs: { span: 24 },
    sm: { span: 7 },
  });
  const wrapperCol = reactive({
    xs: { span: 24 },
    sm: { span: 16 },
  });

  /**
   * 明细事件
   */
  function handleList(record: Recordable) {
    openDrawer(true, {
      record,
    });
  }

  /**
   * 操作栏
   */
  function getTableAction(record) {
    return [
      {
        label: '消费明细',
        icon: 'ant-design:unordered-list-outlined',
        onClick: handleList.bind(null, record),
      },
    ];
  }

  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }
  
  /**
   * 重置
   */
  function searchReset() {
    queryParam.value = {};
    selectedRowKeys.value = [];
    //刷新数据
    reload();
  }

</script>

<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    margin-bottom: -10px;
    .table-page-search-submitButtons {
      display: block;
      white-space: nowrap;
    }
    .query-group-cust{
      width: calc(50% - 15px);
      min-width: 100px !important;
    }
    .query-group-split-cust{
      width: 30px;
      display: inline-block;
      text-align: center
    }
  }
</style>
